import { SUCCESS_CODE } from '@/core/constants/coreConstants'

import { R } from '@/components/axios/interface'
import UpmsMenuAndAuthorityResponse from '@/core/upms/types/model/response/UpmsMenuAndAuthorityResponse'
import UpmsAuthorityResponse from '@/core/upms/types/model/response/UpmsAuthorityResponse'
import UpmsMenuResponse from '@/core/upms/types/model/response/UpmsMenuResponse'
import UpmsMenuAndAuthorityTree from '@/core/upms/types/model/dto/UpmsMenuAndAuthorityTree'
import treeUtils from '@/core/utils/treeUtils'
import idUtils from '@/core/utils/idUtils'
import UpmsConstants from '@/core/oauth2/constants/UpmsConstants'
import UpmsMenuShowStatusEnum from '@/core/upms/enums/UpmsMenuShowStatusEnum'
import oauth2MenuMock from './menus/oauth2MenuMock'
import demoMenuMock from './menus/demoMenuMock'
import applicationMenuMock from './menus/applicationMenuMock'
import captchaMenuMock from './menus/captchaMenuMock'
import upmsMenuMock from './menus/upmsMenuMock'
import accountMenuMock from './menus/accountMenuMock'
import ossMenuMock from './menus/ossMenuMock'
import smsMenuMock from './menus/smsMenuMock'
import captchaSmsMenuMock from './menus/captchaSmsMenuMock'
import { MockMethod } from 'vite-plugin-mock'
import mockProdServerUtils from '../utils/mockUtils'
import upmsApiConfig from '@/core/upms/apiconfig/upmsApiConfig'

const timeout = 50

const mockList = [
	// 获取全部菜单接口
	{
		url: upmsApiConfig.upmsMenu.getAllAdminMenuByCurrentAccount.mockUri,
		method: upmsApiConfig.upmsMenu.getAllAdminMenuByCurrentAccount.method,
		timeout,
		response: ({ body }: any) => {
			const menuTree: UpmsMenuAndAuthorityTree[] = [
				{
					menu: {
						title: '首页',
						icon: 'fa fa-home',
						sort: 0,
						showStatus: UpmsMenuShowStatusEnum.DISPLAY.getCode(),
						uri: '/home',
					} as Partial<UpmsMenuResponse>,
					authority: {} as UpmsAuthorityResponse,
					children: [],
				},
				...applicationMenuMock,
				...oauth2MenuMock,
				...accountMenuMock,
				...upmsMenuMock,
				...captchaMenuMock,
				...captchaSmsMenuMock,
				...smsMenuMock,
				...ossMenuMock,
				...demoMenuMock,
			]

			const converter = (node: UpmsMenuAndAuthorityTree, parentNode?: UpmsMenuAndAuthorityTree): UpmsMenuAndAuthorityResponse => {
				const result = {
					menu: node.menu,
					authority: node.authority,
				} as UpmsMenuAndAuthorityResponse
				result.menu.id = idUtils.generateStringId()
				result.menu.parentId = parentNode ? parentNode.menu.id! : UpmsConstants.ROOT_PARENT_ID
				return result
			}
			const menuArray: UpmsMenuAndAuthorityResponse[] = treeUtils.toArray(menuTree, converter)

			return {
				code: SUCCESS_CODE,
				data: menuArray,
			} as R<UpmsMenuAndAuthorityResponse[]>
		},
	},
] as MockMethod[]

mockProdServerUtils.addPriorityMockList(1, ...mockList)
